package com.gc.service.impl;

import com.gc.dao.ResumeDao;
import com.gc.pojo.Resume;
import com.gc.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ResumeServiceImpl implements ResumeService {

    @Autowired
    private ResumeDao resumeDao;

    @Override
    public List<Resume> findAll() {
        return resumeDao.findAll();
    }


    @Override
    public void deleteById(Long id) {
        resumeDao.deleteById(id);
    }

    /**
     * 如果有id就是修改， 否则就是新增
     * @param resume 之后的对象
     * @return
     */
    @Override
    public Resume save(Resume resume) {
        return resumeDao.save(resume);
    }

    @Override
    public Resume findById(Long id) {
        Resume resume=new Resume();
        resume.setId(id);
        Example<Resume> example = Example.of(resume);
        Optional<Resume> optional = resumeDao.findOne(example);
        if (optional.isPresent()){
            return  optional.get();
        }
        return  null;
    }
}
